package com.bkfm;

import java.util.HashMap;

import org.json.JSONObject;
import org.yak.common.file.FileUtil;

import com.baidu.aip.ocr.AipOcr;
import com.bkfm.baidu.BaiDuAction.BAIDU_IMAGES_WORDS;


public class BaiduAPIDemo {

	public static void main(String args[]) {
		AipOcr client = new AipOcr(BAIDU_IMAGES_WORDS.AppID,BAIDU_IMAGES_WORDS.API_KEY, BAIDU_IMAGES_WORDS.SECRET_KEY);
		// 传入可选参数调用接口
	    HashMap<String, String> options = new HashMap<String, String>();
	    options.put("recognize_granularity", "big");
	    options.put("detect_direction", "true");
	    options.put("vertexes_location", "true");
	    options.put("probability", "true");
	    
	    try {
		    // 参数为本地路径
		    String image = "d:\\555.jpg";
		    JSONObject res = client.accurateGeneral(image, options);
		    System.out.println(res.toString(2));
	
		    // 参数为二进制数组
		    /*byte[] file = FileUtil.readFile2Byte("d:\\sfzh.jpg");
		    JSONObject res2 = client.idcard(file, BAIDU_IMAGES_WORDS.IDCARDSIDE_FRONT, options);//client.idcard(card_file_path, BAIDU_IMAGES_WORDS.IDCARDSIDE_FRONT, options);
		    System.out.println(res2.toString(2));*/
	    }catch(Exception e) {
	    	e.printStackTrace();
	    }
	}
}
